package com.gpms.action.paper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.gpms.bean.Teacher;
import com.gpms.bean.TeacherTimePoint;
import com.gpms.bean.Topics;
import com.gpms.service.Topics.IShowTopicsListService;
import com.gpms.service.Topics.TopicsListFactory;
import com.gpms.service.systemInit.IAdminOperateFactory;
import com.gpms.service.systemInit.ISingleTime;
import com.gpms.service.systemInit.SetTimeFactory;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class PlatformTimeAction extends ActionSupport 
{
	private List<Topics> topicss;
	private List<TeacherTimePoint> teacherTimePoint;
	
	public List<Topics> getTopicss() {
		return topicss;
	}
	public void setTopicss(List<Topics> topicss) {
		this.topicss = topicss;
	}
	public List<TeacherTimePoint> getTeacherTimePoint() {
		return teacherTimePoint;
	}
	public void setTeacherTimePoint(List<TeacherTimePoint> teacherTimePoint) {
		this.teacherTimePoint = teacherTimePoint;
	}

	@Override
	public String execute() throws Exception {
		Map session = ActionContext.getContext().getSession();
		Teacher teacher = (Teacher)session.get("user");
		IShowTopicsListService operate = TopicsListFactory.createTopicsList("TeacherTopicsList");
		List<Topics> topicss = operate.showITopicsList(teacher.getTeacherNum(), "taskBook");
		IAdminOperateFactory factory = new SetTimeFactory();
		ISingleTime setTime = (ISingleTime)factory.create("single");
		List<TeacherTimePoint> teacherTimePoint = new ArrayList<TeacherTimePoint>();
		for(Topics topics : topicss)
		{
			TeacherTimePoint timePoint = setTime.showTimePoint(topics, 13);
			teacherTimePoint.add(timePoint);
		}
		setTopicss(topicss);
		setTeacherTimePoint(teacherTimePoint);
		return "success";
	}
	public String setPlatfomrTime() throws Exception {
		String result="success";
		List<Topics> topicss = getTopicss();
		List<TeacherTimePoint> teacherTimePoint = getTeacherTimePoint();
		IAdminOperateFactory factory = new SetTimeFactory();
		ISingleTime setTime = (ISingleTime)factory.create("single");
		result = setTime.set(topicss, teacherTimePoint);
		return result;
	}
}
